﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Hangjing.Common;
using Hangjing.SQLServerDAL;
using Hangjing.Model;
using System.Collections.Generic;

public partial class Admin_manage_delivergetfeeconfig : System.Web.UI.Page
{
    Hangjing.SQLServerDAL.citydeliverexpressFeeConfig dal = new Hangjing.SQLServerDAL.citydeliverexpressFeeConfig();
    protected void Page_Load(object sender, EventArgs e)
    {
        ValidatorSet validator = new ValidatorSet("Admin");
        validator.SetValidator();

        if (!IsPostBack)
        {
            BindData();
        }
    }

    /// <summary>
    /// 数据绑定
    /// </summary>
    protected void BindData()
    {
        int cityid = HjNetHelper.GetQueryInt("cityid", 0);
        citydeliverexpressFeeConfigInfo info = dal.GetModel(cityid);
        if (info != null)
        {
            tbbasedistance.Text = info.basedistance.ToString();
            tbbasedistanceprice.Text = info.basedistanceprice.ToString();
            tbseconddistance.Text = info.seconddistance.ToString();
            tbseconddistancePerPrice.Text = info.seconddistancePerPrice.ToString();
            tbthirdDistancePerPrice.Text = info.thirdDistancePerPrice.ToString();
            tbstarttime1.Text = info.starttime1.ToShortTimeString();
            tbendtime1.Text = info.endtime1;
            tbstarttime2.Text = info.starttime2.ToShortTimeString();
            tbendtime2.Text = info.endtime2;
            tbreveint1.Text = info.reveint1.ToString();
            tbreveint2.Text = info.reveint2.ToString();
        }
    }

    protected void btSave_Click(object sender, EventArgs e)
    {

        int _rs = WebUtility.checkOperator_super(5);
        if (_rs == 0)
        {
            AlertScript.RegScript(this.Page, "alert('无操作权限','success','true',5);init();");
            return;
        }


        int cityid = HjNetHelper.GetQueryInt("cityid", 0);
        citydeliverexpressFeeConfigInfo info = dal.GetModel(cityid);
        if (info == null)
        {
            info = new citydeliverexpressFeeConfigInfo();
        }
        info.cityid = cityid;
        info.basedistance = WebUtility.InputText(tbbasedistance.Text, true);
        info.basedistanceprice = WebUtility.InputText(tbbasedistanceprice.Text, 't');
        info.seconddistance = WebUtility.InputText(tbseconddistance.Text, true);
        info.seconddistancePerPrice = WebUtility.InputText(tbseconddistancePerPrice.Text, 't');
        info.thirdDistancePerPrice = WebUtility.InputText(tbthirdDistancePerPrice.Text, 't');
        info.starttime1 = Convert.ToDateTime(tbstarttime1.Text);
        info.endtime1 = tbendtime1.Text;
        info.starttime2 = Convert.ToDateTime(tbstarttime2.Text);
        info.endtime2 = tbendtime2.Text;
        info.reveint1 = WebUtility.InputText(tbreveint1.Text, true);
        info.reveint2 = WebUtility.InputText(tbreveint2.Text, true);
        info.reveint3 = 0;
        info.reveint4 = 0;
        info.revevar1 = "";
        info.revevar2 = "";
        info.revevar3 = "";
        info.revefloat1 = 0;
        info.revefloat2 = 0;
        info.revedate1 = Convert.ToDateTime("1970-1-1");
        info.revedate2 = Convert.ToDateTime("1970-1-1");

        dal.Add(info);

        AlertScript.RegScript(this.Page, UpdatePanel1, "alert('保存成功');init();");

    }

    protected void resume_Click(object sender, EventArgs e)
    {
        int cityid = HjNetHelper.GetQueryInt("cityid", 0);

        expressFeeConfigInfo info = new expressFeeConfig().GetModel(cityid);
        if (info == null)
        {
            AlertScript.RegScript(this.Page, UpdatePanel1, "alert('此城市未设置距离规则，不能还原');init();");
            return;
        }

        WebUtility.excutesql("DELETE citydeliverexpressFeeConfig WHERE cityid = " + cityid);

        info.cityid = cityid;

        dal.Add(info);

        AlertScript.RegScript(this.Page, UpdatePanel1, "alert('保存成功');gourl('delivergetfeeconfig.aspx?cityid=" + cityid + "');");

    }
}
